package com.css.fxfzdpzs.modules.czt.repository.impl;

import com.css.fxfzdpzs.modules.czt.entity.DestructiveStateEntity;
import com.css.fxfzdpzs.modules.czt.entity.first.*;
import com.css.fxfzdpzs.modules.czt.entity.second.*;
import com.css.fxfzdpzs.modules.czt.vo.CztSystemSituation;
import com.css.fxfzdpzs.modules.czt.repository.CztRepository;
import com.css.fxfzdpzs.modules.czt.vo.DestructiveStateVo;
import com.css.fxfzdpzs.modules.czt.vo.VulnerabilityCompletenessVo;
import org.springframework.http.HttpEntity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @description
 */
@Repository
public class CztRepositoryImpl implements CztRepository {


    @Resource
    JdbcTemplate jdbcTemplate;

    @Override
    public List<CztMonomerBuildNum> getBuildNum() {
        String sql = "select * from czt_number_of_individual_buildings ";
        List<CztMonomerBuildNum> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CztMonomerBuildNum.class));
        return list;
    }

    @Override
    public List<CztProvinceVulnerabilityCount> getVulnerabilityCount() {
        String sql = "select * from czt_vulnerability_of_lifelines ";
        List<CztProvinceVulnerabilityCount> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CztProvinceVulnerabilityCount.class));
        return list;
    }

    @Override
    public List<CztBeijingVulnerabilityCurve> getVulnerabilityCurve(String province) {
        String sql = "select * from czt_beijing_vulnerability_curve where province ='" + province + "' ";
        List<CztBeijingVulnerabilityCurve> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CztBeijingVulnerabilityCurve.class));
        return list;
    }

    @Override
    public List<CztSmgcVulnerabilityNum> getVulnerabilityNum() {
        String sql = "select * from czt_number_of_lifelines ";
        List<CztSmgcVulnerabilityNum> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CztSmgcVulnerabilityNum.class));
        return list;
    }

    @Override
    public List<CztSystemSituation> getSystemSituation() {
        String sql = "select * from czt_collection_system_situation ";
        List<CztSystemSituation> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(CztSystemSituation.class));
        return list;
    }

    @Override
    public List<String> getProvince() {
        String sql = "select distinct  province from czt_beijing_vulnerability_curve ";
        List<String> list = jdbcTemplate.queryForList(sql, String.class);
        return list;
    }

    @Override
    public List<DamageGrade> getProportion() {
        String sql = "select * from czt_damage_grade ";
        List<DamageGrade> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DamageGrade.class));
        return list;
    }

    @Override
    public List<VulnerabilityCompletenessVo> getCompleteness() {
        String sql = "select province,code,completeness from czt_vulnerability_completeness";
        List<VulnerabilityCompletenessVo> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(VulnerabilityCompletenessVo.class));
        return list;
    }

    @Override
    public List<SeismicResistance> getSeismicResistance(String level) {
        String sql = "select province,code,level,degrees from czt_seismic_resistance where level ='" + level + "'";
        List<SeismicResistance> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SeismicResistance.class));
        return list;
    }

    @Override
    public void updateUrl(String id, String newUrl) {
        String sql = "update czt_vulnerability_data set video = '" + newUrl + "' where id = '" + id + "'";
        jdbcTemplate.update(sql);
    }

    @Override
    public List<FortificationEntity> getAllFortification() {
        String sql = "select * from czt_seismic_fortification_of_buildings ";
        List<FortificationEntity> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(FortificationEntity.class));
        return list;
    }

    @Override
    public void saveState(DestructiveStateEntity entity) {
        jdbcTemplate.update("insert into czt_destructive_state  (id,county_name,county_code,basically,minor,moderate,serious,collapse,province_code,intensity,basically_percentage,minor_percentage,moderate_percentage,serious_percentage,collapse_percentage,province_area,destructive_state,province ) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )",
                entity.getId(), entity.getCountyName(), entity.getCountyCode(), entity.getBasically(), entity.getMinor(), entity.getModerate(), entity.getSerious(), entity.getCollapse(),entity.getProvinceCode(),entity.getIntensity(),entity.getBasicallyPercentage(),entity.getMinorPercentage(),entity.getModeratePercentage(),entity.getSeriousPercentage(),entity.getCollapsePercentage(),entity.getProvinceArea(),entity.getDestructiveState(),entity.getProvince());
    }

    @Override
    public void delState() {
        String sql = "delete from czt_destructive_state";
        jdbcTemplate.update(sql);
    }

    @Override
    public List<DestructiveStateVo> seismicResistance() {
        String sql = "select intensity,county_code,destructive_state from czt_destructive_state";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DestructiveStateVo.class));
    }

    @Override
    public List<DestructiveStateEntity> getAllState() {
        String sql = "select * from czt_destructive_state";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(DestructiveStateEntity.class));
    }
}
